package get

import (
	"database/sql"

	"github.com/gin-gonic/gin"
)

func Get_type(r *gin.Engine) {
	var db *sql.DB
	var err error
	var sid, mal, date string = "0", "0", "0"

	db, err = sql.Open("postgres", "port=5432 user=postgres password=system dbname=databasedesign sslmode=disable")
	if err != nil {
		panic(err)
	}

	// 获取搜索
	r.GET("/gettype", func(c *gin.Context) {
		xx := c.Query("xx")
		if xx != "" {

			str := "SELECT * FROM test where sid='" + xx + "'"
			rows, err := db.Query(str)
			if err != nil {
				panic(err)
			}

			for rows.Next() {

				err = rows.Scan(&sid, &mal, &date)
				if err != nil {
					panic(err)
				}

				c.JSON(200, gin.H{
					"sid":  sid,
					"mal":  mal,
					"date": date,
				})
			}
		}
	})
}
